<?php

namespace App\Http\Controllers\Customer\Pages;

use Illuminate\Http\Request;
use App\Facades\DeviceService;
use App\Facades\WeChatService;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class DeviceController extends Controller
{
    //选择设备型号页面
    public function index(Request $request)
    {
        return view('deviceSelect');
    }

    //配网页面
    public function connect(Request $request)
    {
        return view('connect-'.$request->type)->with(wxConfig(['type' => $request->type], $request));
    }

    //绑定页面
    public function bind(Request $request)
    {
        return view('bind')->with(wxConfig(['type' => $request->type], $request));
    }

    //水机控制页面
    public function getState(Request $request)
    {
        $state = DeviceService::getStateByType($request->type, 'state');
        if(is_null($state)){
            $state['deviceCode'] = deviceCode($request->type);
        }
        $host = head($request->header()['host']);
        return view('state')->with(wxConfig([
            'state' => $state, 
            'host' => $host,
            'type' => $request->type,
            ], $request));
    }
    //水机滤芯页面 filters1508
    public function getFilters(Request $request)
    {
        $state = DeviceService::getStateByType($request->type, 'filters');
        $state['deviceCode'] = deviceCode($request->type);
        $host = head($request->header()['host']);
        return view('filter-'.$request->type)->with([
            'state' => $state, 
            'host' => $host,
            'type' => $request->type,
            ]);
    }
    //设备信息
    public function info(Request $request)
    {
        return view('deviceInfor')->with(['type' => $request->type]);
    }

    //解绑页面
    public function unbind(Request $request)
    {
        return view('unbind')->with([
            'type' => $request->type,
            'device_code' => deviceCode($request->type)
            ]);
    }

}
